package top.shmly.universal.base.response;

import org.springframework.security.core.authority.SimpleGrantedAuthority;
import top.shmly.universal.base.common.Result;
import top.shmly.universal.base.common.SysUser;
import top.shmly.universal.config.security.AuthUser;
import top.shmly.universal.utils.impl.Md5UtilsImpl;

import java.util.*;

/**
 * @program: universal
 * @description:
 * @author: Jibny
 * @date 2021-04-25 11:40:18
 */
public class ResponseResult<T> implements IResponseResult<T> {

    @Override
    public Result<T> ok() {
        return Result.<T>builder()
                .code(ResponseCode.CODE_200.getCode())
                .message(ResponseCode.CODE_200.getDesc())
                .success(Boolean.TRUE)
                .build();
    }

    @Override
    public Result<T> ok(String message) {
        return Result.<T>builder()
                .code(ResponseCode.CODE_200.getCode())
                .message(message)
                .success(Boolean.TRUE)
                .build();
    }

    @Override
    public Result<T> ok(ResponseCode resCode) {
        return Result.<T>builder()
                .code(resCode.getCode())
                .message(resCode.getDesc())
                .success(Boolean.TRUE)
                .build();
    }

    @Override
    public Result<T> ok(ResponseCode resCode, T t) {
        return Result.<T>builder()
                .code(resCode.getCode())
                .message(resCode.getDesc())
                .responseData(t)
                .success(Boolean.TRUE)
                .build();
    }

    @Override
    public Result<T> ok(ResponseCode resCode, String message, T t) {
        return Result.<T>builder()
                .code(resCode.getCode())
                .message(message)
                .responseData(t)
                .success(Boolean.TRUE)
                .build();
    }

    @Override
    public Result<T> ok(T t) {
        return Result.<T>builder()
                .code(ResponseCode.CODE_200.getCode())
                .message(ResponseCode.CODE_200.getDesc())
                .responseData(t)
                .success(Boolean.TRUE)
                .build();
    }

    @Override
    public Result<T> fail() {
        return Result.<T>builder()
                .code(ResponseCode.CODE_400.getCode())
                .message(ResponseCode.CODE_400.getDesc())
                .success(Boolean.FALSE)
                .build();
    }

    @Override
    public Result<T> fail(String message) {
        return Result.<T>builder()
                .code(ResponseCode.CODE_400.getCode())
                .message(message)
                .success(Boolean.FALSE)
                .build();
    }

    @Override
    public Result<T> fail(ResponseCode resCode) {
        return Result.<T>builder()
                .code(resCode.getCode())
                .message(resCode.getDesc())
                .success(Boolean.FALSE)
                .build();
    }

    @Override
    public Result<T> fail(ResponseCode resCode, T t) {
        return Result.<T>builder()
                .code(resCode.getCode())
                .message(resCode.getDesc())
                .responseData(t)
                .success(Boolean.FALSE)
                .build();
    }

    @Override
    public Result<T> fail(ResponseCode resCode, String message, T t) {
        return Result.<T>builder()
                .code(resCode.getCode())
                .message(message)
                .responseData(t)
                .success(Boolean.FALSE)
                .build();
    }

    @Override
    public Result<T> fail(T t) {
        return Result.<T>builder()
                .code(ResponseCode.CODE_400.getCode())
                .message(ResponseCode.CODE_400.getDesc())
                .responseData(t)
                .success(Boolean.FALSE)
                .build();
    }


    public static void main(String[] args) {
        IResponseResult<AuthUser> iResponseResult = new ResponseResult<>();
        System.out.println(iResponseResult.ok().toString());
        System.out.println(iResponseResult.ok("NISHUODEDUI").toString());

        Set<SimpleGrantedAuthority> grantedAuthorities = new HashSet<>();
        AuthUser user = new AuthUser("username"
                , "123456", grantedAuthorities);
        System.out.println(iResponseResult.ok(user).toString());

        Map<String, String> map = new HashMap<>();
        map.put("test111", "1111");
        map.put("test222", "2222");
        map.put("test333", "3333");
        IResponseResult<Map<String, String>> iResponseResult1 = new ResponseResult<>();
        System.out.println(iResponseResult1.ok(map).toString());
    }
}
